﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace TMIS
{
    public partial class frmAgency : XtraForm
    {
        private BLL.Angecy bll = new BLL.Angecy();

        public frmAgency()
        {
            InitializeComponent();
            this.FillComponent();

        }

        #region 窗体控件数据初始化填充
        private void FillComponent()
        {
            comCollege.Properties.Items.Clear();
            comDepartment.Properties.Items.Clear();
            comProfession.Properties.Items.Clear();
            comGrade.Properties.Items.Clear();
            comCollege.Properties.Items.Add("兰州商学院长青学院");
            comDepartment.Properties.Items.AddRange(bll.SearchDepartment());
            comProfession.Properties.Items.AddRange(bll.SearchProfession());
            comGrade.Properties.Items.AddRange(bll.SearchGrade());
        }
        #endregion

        private void btnAddDepartment_Click(object sender, EventArgs e)
        {
            try
            {
                if (bll.InsertDepartment(txtDepartment.Text))
                {
                    XtraMessageBox.Show("院系信息添加成功！");
                }
                else
                {
                    XtraMessageBox.Show("院系信息重复！添加失败！");
                }
            }
            catch (Exception error)
            {
                #if DEBUG
                XtraMessageBox.Show(error.Message);
                #else
                XtraMessageBox.Show("院系信息添加失败！");
                #endif
            }
            this.FillComponent();
        }

        private void btnAddProfession_Click(object sender, EventArgs e)
        {
            try
            {
                if(bll.InsertProfession(txtProfession.Text, bll.SearchDepartment(comDepartment.Text)))
                {
                    XtraMessageBox.Show("专业信息添加成功！");
                }
                else
                {
                    XtraMessageBox.Show("专业信息重复！添加失败！");
                }
            }
            catch (Exception error)
            {
                #if DEBUG
                XtraMessageBox.Show(error.Message);
                #else
                XtraMessageBox.Show("专业信息添加失败！");
                #endif
            }
            this.FillComponent();
        }

        private void btnAddGrade_Click(object sender, EventArgs e)
        {
            try
            {
                if (bll.InsertGrade(txtGrade.Text,txtSimply.Text, bll.SearchProfession(comProfession.Text)))
                {
                    XtraMessageBox.Show("年级信息添加成功！");
                }
                else
                {
                    XtraMessageBox.Show("年级信息重复！添加失败！");
                }
            }
            catch (Exception error)
            {
                #if DEBUG
                XtraMessageBox.Show(error.Message);
                #else
                XtraMessageBox.Show("年级信息添加失败！");
                #endif
            }
            this.FillComponent();
        }

        private void btnAddClass_Click(object sender, EventArgs e)
        {
            try
            {
                if (bll.InsertClass(txtClass.Text, bll.SearchGrade(comGrade.Text)))
                { 
                    XtraMessageBox.Show("班级信息添加成功！");
                }
                else
                {
                    XtraMessageBox.Show("班级信息重复！添加失败！");
                }
            }
            catch (Exception error)
            {
                #if DEBUG
                XtraMessageBox.Show(error.Message);
                #else
                XtraMessageBox.Show("班级信息添加失败！");
                #endif
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }


    }
}
